import requests
import json
url = 'https://m.douban.com/rexxar/api/v2/subject/recent_hot/movie'
params = {
    'start':0,
    'limit':20,
    'ck':'efdK'
}
headers = {
    "origin": "https://movie.douban.com",
    "priority": "u=1, i",
    "referer": "https://movie.douban.com/explore",
    "sec-ch-ua": '"Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138"',
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": '"Windows"',
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
}

resp = requests.get(url,params=params,headers=headers)
print(resp.text)
#转换为了字典
d = json.loads(resp.text)
#转换为字符串
# s = json.dumps(d,indent=4,ensure_ascii=False)
# print(s)
index = 1
for i in range(0,320,20):
    with open(f'data/movie{index}.json','w',encoding='utf-8') as f:
        json.dump(d,f,ensure_ascii=False,indent=4)
    index+=1